package com.jsdx.td.controller;

import com.jsdx.td.common.ApiResponse;
import com.jsdx.td.entity.User;
import com.jsdx.td.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @作者 TD
 * @日期 2025/2/28
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/test")
public class UserController {

    private final UserService userService;

    @GetMapping ( value = "/users", produces = "application/json;charset=UTF-8")
    public ApiResponse getUsers(){
        return userService.getUsers() ;
    }

    @GetMapping("/users/{id}")
    public ApiResponse getUserById(@PathVariable Integer id){
        return userService.getUserById(id);
    }

    @PostMapping("/users")
    public ApiResponse addUser(@RequestBody User user){
        return userService.addUser(user);
    }

    @PutMapping("/users/{id}")
    public ApiResponse updateUser(@PathVariable Integer id,@RequestBody User user){
        return userService.updateUser(id,user);
    }

    @DeleteMapping("/users/{id}")
    public ApiResponse deleteUser(@PathVariable Integer id){
        return userService.deleteUser(id);
    }


}
